import {reqGoodDetailInfoData} from '../../api'
  

const  state = {
    goodDetailInfo:{}  
    /* 
       使用到的数据对象里面有用的是：categoryView，skuInfo，spuSaleAttrList
            1. categoryView：图片上方的分类条
                    category1Id:2
                    category1Name:"手机"
                    category2Id:13
                    category2Name:"手机通讯"
                    category3Id:61
                    category3Name:"手机"
                    id:61
            price:4488

                    
            2. skuInfo中：
            1. skuName    商品名称
            2. skuDesc      商品描述
            3. price            商品价格
            4. skuImageList      商品图片组
            5. skuDefaultImg     放大镜的图片

              

            3. spuSaleAttrList：平台属性(嵌套数组)
                attrId:106
                attrName:"手机一级"
                id:57
                skuId:15
                valueId:176
                valueName:"安卓手机"
    */
}

const  actions = {
    async  getGoodDetailInfoData({commit},id){
        const  result = await  reqGoodDetailInfoData(id)
        if(result.code === 200){
             commit('SAVE_GOOD_DETAIL_INFO_DATA',result.data)
        }else{
             console.log(result.message);
        }
    }
}

const  mutations = {
    SAVE_GOOD_DETAIL_INFO_DATA(state,payload){
        state.goodDetailInfo = payload  //请求回来的数据是对象形式
    }
}

const getters= { 
    categoryView(state){
         return state.goodDetailInfo.categoryView || {}
    },
    skuInfo(state){
           return state.goodDetailInfo.skuInfo || {}
    },
    spuSaleAttrList(state){
           return state.goodDetailInfo.spuSaleAttrList || {}
    }

}



export default {
    namespaced:true,//开启命名空间
    state,
    actions,
    mutations,
    getters,
}